home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- Smaller Installer © 1996 Bill Goodman, All Rights Reserved
- *******************************************************************************
-
- Demonstration Hook Example
-
- This is an example of an installer hook procedure. It displays an alert each
- time the hook procedure is called.
-
- To build this hook procedure, compile this code and create a code resource
- (Type:SICR, ID:501, non-preloaded, nonpurgeable, unlocked, unprotected,
- non-sysheap). Add this resource to the "DemoHook.rsrc" file. Copy all the
- resources in "DemoHook.rsrc" to your installer's resource file.
-
- ******************************************************************************/
-
- // This file is compatible with version 2.1 of the universal headers
- #include <Dialogs.h>
- #include <Files.h>
- #include <TextUtils.h>
-
- #ifdef __MWERKS__
- #include <A4Stuff.h>
- #endif
-
- #ifdef THINK_C
- #include <SetUpA4.h>
- #endif
-
- #include "SIHookProc.h"
-
-
- /******************************************************************************
- Module Internal Function Prototypes
- ******************************************************************************/
- void AfterItemFunction(void);
- void BeforeItemFunction(void);
- void BeginOperationFunction(void);
- void BuildGroupStrings(StringPtr selGroupStr, StringPtr envGroupStr);
- void BuildItemString(StringPtr nameStr);
- void ChangeSelectionFunction(void);
- void EndOperationFunction(void);
- void FirstFunction(void);
- void GetDesDirName(StringPtr dirStr);
- void GetVolName(short vRefNum, StringPtr volStr);
- void LastFunction(void);
- void StrAppend(StringPtr srcStr, StringPtr desStr);
-
-
- /******************************************************************************
- Constant Definitions
- ******************************************************************************/
- // Alert Definitions
- #define firstAlrt 500 // Resource ID of First alert
- #define quit_firstAlrt 2 // Item number of QUIT button
-
- #define lastAlrt 501 // Resource ID of Last alert
-
- #define changeAlrt 502 // Resource ID of ChangeSelection alert
- #define quit_changeAlrt 2 // Item number of QUIT button
-
- #define beginOpAlrt 503 // Resource ID of BeginOperation alert
- #define abort_beginOpAlrt 2 // Item number of ABORT button
- #define quit_beginOpAlrt 3 // Item number of QUIT button
-
- #define beforeItemAlrt 504 // Resource ID of BeforeItem alert
- #define skip_beforeItemAlrt 2 // Item number of SKIP button
- #define skipN_beforeItemAlrt 3 // Item number of ITEMDONE button
- #define abort_beforeItemAlrt 4 // Item number of ABORT button
- #define quit_beforeItemAlrt 5 // Item number of QUIT button
-
- #define afterItemAlrt 505 // Resource ID of AfterItem alert
- #define abort_afterItemAlrt 2 // Item number of ABORT button
- #define quit_afterItemAlrt 3 // Item number of QUIT button
-
- #define endOpAlrt 506 // Resource ID of EndOperation alert
- #define abort_endOpAlrt 2 // Item number of ABORT button
- #define quit_endOpAlrt 3 // Item number of QUIT button
-
-
- /******************************************************************************
- Module Variable Definitions
- ******************************************************************************/
- SIHookParmBlk *gParms; // Global pointer to parameter block
- unsigned char gEmptyStr[] = "\p"; // Global empty string
-
-
- /*****************************************************************************/
- pascal void main(
- SIHookParmBlk *parmBlk // Pointer to parameter block
- )
- /******************************************************************************
- This is the main entry point for the installer hook procedure.
- ******************************************************************************/
- {
- #ifdef __MWERKS__
- long holdA4;
- #endif
-
- // Set up access to global variables
- #ifdef THINK_C
- RememberA0();
- SetUpA4();
- #endif
-
- #ifdef __MWERKS__
- holdA4 = SetCurrentA4();
- #endif
-
- gParms = parmBlk;
-
- switch (gParms->function)
- {
- case siHookFirst:
- FirstFunction();
- break;
-
- case siHookLast:
- LastFunction();
- break;
-
- case siHookChangeSelection:
- ChangeSelectionFunction();
- break;
-
- case siHookBeginOperation:
- BeginOperationFunction();
- break;
-
- case siHookBeforeItem:
- BeforeItemFunction();
- break;
-
- case siHookAfterItem:
- AfterItemFunction();
- break;
-
- case siHookEndOperation:
- EndOperationFunction();
- break;
- }
-
- // Restore original A4 value
- #ifdef THINK_C
- RestoreA4();
- #endif
-
- #ifdef __MWERKS__
- SetA4(holdA4);
- #endif
- }
-
-
- /*****************************************************************************/
- void FirstFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
-
- Returns:
- "groupAPFlags" Updated installation groups
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "result" Hook result code (siHookNoErr, siHookQuit)
-
- This function is called once when the installer is launched.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 selectedGroupsStr;
- Str255 environGroupsStr;
-
- GetVolName(gParms->targetVRefNum, volumeStr);
- BuildGroupStrings(selectedGroupsStr, environGroupsStr);
-
- // Display the target volume name and the selected groups in an alert
- ParamText(volumeStr, selectedGroupsStr, environGroupsStr, gEmptyStr);
- if (Alert(firstAlrt, NULL) == quit_firstAlrt)
- gParms->result = siHookQuit;
- // Note that it is not necessary to set "result" if no error
- }
-
-
- /*****************************************************************************/
- void LastFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
-
- Returns:
- Nothing
-
- This function is called once when the installer is terminating execution.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 selectedGroupsStr;
- Str255 environGroupsStr;
-
- GetVolName(gParms->targetVRefNum, volumeStr);
- BuildGroupStrings(selectedGroupsStr, environGroupsStr);
-
- // Display the target volume name and the selected groups in an alert
- ParamText(volumeStr, selectedGroupsStr, environGroupsStr, gEmptyStr);
- Alert(lastAlrt, NULL);
- }
-
-
- /*****************************************************************************/
- void ChangeSelectionFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
-
- Returns:
- "groupAPFlags" Updated installation groups
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "result" Hook result code (siHookNoErr, siHookQuit)
-
- This function is called whenever the target volume or group selections are
- changed.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 selectedGroupsStr;
- Str255 environGroupsStr;
-
- GetVolName(gParms->targetVRefNum, volumeStr);
- BuildGroupStrings(selectedGroupsStr, environGroupsStr);
-
- // Display the target volume name and the selected groups in an alert
- ParamText(volumeStr, selectedGroupsStr, environGroupsStr, gEmptyStr);
- if (Alert(changeAlrt, NULL) == quit_changeAlrt)
- gParms->result = siHookQuit;
- }
-
-
- /*****************************************************************************/
- void BeginOperationFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "passwordPtr" Pointer to password string
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
-
- Returns:
- "passwordPtr" Pointer to password string
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort)
-
- This function is called when the install button or the remove button is
- clicked to begin installing or removing files.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 selectedGroupsStr;
- Str255 environGroupsStr;
- Str255 statusStr;
-
- GetVolName(gParms->targetVRefNum, volumeStr);
- BuildGroupStrings(selectedGroupsStr, environGroupsStr);
-
- // Build status string
- statusStr[0] = 0;
- StrAppend("\pDoingRemove: ", statusStr);
- StrAppend(gParms->doingRemove ? "\pTRUE" : "\pFALSE", statusStr);
-
- // Display the target volume name, the selected groups and "doingRemove" in an
- // alert
- ParamText(volumeStr, selectedGroupsStr, environGroupsStr, statusStr);
- switch (Alert(beginOpAlrt, NULL))
- {
- case abort_beginOpAlrt:
- gParms->result = siHookAbort;
- break;
-
- case quit_beginOpAlrt:
- gParms->result = siHookQuit;
- break;
- }
- }
-
-
- /*****************************************************************************/
- void BeforeItemFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
- "anyItemsSkipped" Non-zero if any item has been skipped during operation
- "desVRefNum" Volume reference number of destination volume
- "desDirID" Directory ID of destination directory
- "itemName" Name of item to install or remove
- "itemIsFolder" Non-zero if item is a folder
- "fileType" File type (files only)
- "fileCreator" File creator (files only)
- "createDate" Creation date (files only)
- "lastModDate" Last modification date (files only)
- "rsrcForkLen" Length of resource fork (files only)
- "dataForkLen" Length of data fork (files only)
-
- Returns:
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort, siHookSkip, siHookItemDone)
- "desDirID" Directory ID of destination directory
- "itemName" Name of item to install or remove
- "itemInfo" Reference passed to AfterItem call
-
- This function is called before each item is installed or removed.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 dirStr;
- Str255 itemStr;
- Str255 statusStr;
-
- GetVolName(gParms->desVRefNum, volumeStr);
- GetDesDirName(dirStr);
- BuildItemString(itemStr);
-
- // Build status string
- statusStr[0] = 0;
- StrAppend("\pDoingRemove: ", statusStr);
- StrAppend(gParms->doingRemove ? "\pTRUE\r" : "\pFALSE\r", statusStr);
- StrAppend("\pAnyItemsSkipped: ", statusStr);
- StrAppend(gParms->anyItemsSkipped ? "\pTRUE" : "\pFALSE", statusStr);
-
- // Display the destination volume name, destination directory name, item name,
- // "doingRemove" and "anyItemsSkipped" in an alert.
- ParamText(volumeStr, dirStr, itemStr, statusStr);
- switch (Alert(beforeItemAlrt, NULL))
- {
- case skip_beforeItemAlrt:
- gParms->result = siHookSkip;
- break;
-
- case skipN_beforeItemAlrt:
- gParms->result = siHookItemDone;
- break;
-
- case abort_beforeItemAlrt:
- gParms->result = siHookAbort;
- break;
-
- case quit_beforeItemAlrt:
- gParms->result = siHookQuit;
- break;
- }
- }
-
-
- /*****************************************************************************/
- void AfterItemFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
- "anyItemsSkipped" Non-zero if any item has been skipped during operation
- "itemWasSkipped" Non-zero if this item was skipped
- "desVRefNum" Volume reference number of destination volume
- "desDirID" Directory ID of destination directory
- "itemName" Name of item that was installed or removed
- "itemIsFolder" Non-zero if item is a folder
- "fileType" File type (files only)
- "fileCreator" File creator (files only)
- "createDate" Creation date (files only)
- "lastModDate" Last modification date (files only)
- "rsrcForkLen" Length of resource fork (files only)
- "dataForkLen" Length of data fork (files only)
- "itemInfo" Reference passed from BeforeItem call
-
- Returns:
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort)
-
- This function is called after each item is installed or removed.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 dirStr;
- Str255 itemStr;
- Str255 statusStr;
-
- GetVolName(gParms->desVRefNum, volumeStr);
- GetDesDirName(dirStr);
- BuildItemString(itemStr);
-
- // Build status string
- statusStr[0] = 0;
- StrAppend("\pDoingRemove: ", statusStr);
- StrAppend(gParms->doingRemove ? "\pTRUE\r" : "\pFALSE\r", statusStr);
- StrAppend("\pAnyItemsSkipped: ", statusStr);
- StrAppend(gParms->anyItemsSkipped ? "\pTRUE\r" : "\pFALSE\r", statusStr);
- StrAppend("\pItemWasSkipped: ", statusStr);
- StrAppend(gParms->itemWasSkipped ? "\pTRUE" : "\pFALSE", statusStr);
-
- // Display the destination volume name, destination directory name, item name,
- // "doingRemove", "anyItemsSkipped" and "itemWasSkipped" in an alert.
- ParamText(volumeStr, dirStr, itemStr, statusStr);
- switch (Alert(afterItemAlrt, NULL))
- {
- case abort_afterItemAlrt:
- gParms->result = siHookAbort;
- break;
-
- case quit_afterItemAlrt:
- gParms->result = siHookQuit;
- break;
- }
- }
-
-
- /*****************************************************************************/
- void EndOperationFunction(void)
- /******************************************************************************
- Input parameters:
- "targetVRefNum" Volume reference number of target volume
- "groupAPFlags" Groups currently selected
- "groupQUSel"
- "groupVZSel"
- "group32Flags"
- "group64Flags"
- "group96Flags"
- "groupEnvironFlags"
- "filesRemaining" Number of files remaining to install or remove
- "bytesRemaining" Number of bytes of data remaining to install or remove
- "doingRemove" Non-zero if doing remove operation
- "anyItemsSkipped" Non-zero if any item has been skipped during operation
- "aborted" Non-zero if operation was aborted
-
- Returns:
- "result" Hook result code (siHookNoErr, siHookQuit, siHookAbort)
-
- This function is called at the end of the install or remove operation.
- ******************************************************************************/
- {
- Str255 volumeStr;
- Str255 selectedGroupsStr;
- Str255 environGroupsStr;
- Str255 statusStr;
-
- GetVolName(gParms->targetVRefNum, volumeStr);
- BuildGroupStrings(selectedGroupsStr, environGroupsStr);
-
- // Build status string
- statusStr[0] = 0;
- StrAppend("\pDoingRemove: ", statusStr);
- StrAppend(gParms->doingRemove ? "\pTRUE\r" : "\pFALSE\r", statusStr);
- StrAppend("\pAnyItemsSkipped: ", statusStr);
- StrAppend(gParms->anyItemsSkipped ? "\pTRUE\r" : "\pFALSE\r", statusStr);
- StrAppend("\pAborted: ", statusStr);
- StrAppend(gParms->aborted ? "\pTRUE" : "\pFALSE", statusStr);
-
- // Display the target volume name, the selected groups, "doingRemove",
- // "anyItemsSkipped" and "aborted" in an alert
- ParamText(volumeStr, selectedGroupsStr, environGroupsStr, statusStr);
- switch (Alert(endOpAlrt, NULL))
- {
- case abort_endOpAlrt:
- gParms->result = siHookAbort;
- break;
-
- case quit_endOpAlrt:
- gParms->result = siHookQuit;
- break;
- }
- }
-
-
- /*****************************************************************************/
- void GetVolName(
- short vRefNum, // Source volume reference number
- StringPtr volStr // Returned volume name string
- )
- /******************************************************************************
- Get name of specified volume and return in the specified string.
- ******************************************************************************/
- {
- HParamBlockRec pb;
-
- pb.volumeParam.ioVRefNum = vRefNum;
- pb.volumeParam.ioNamePtr = volStr;
- pb.volumeParam.ioVolIndex = 0;
- if (PBHGetVInfoSync(&pb))
- volStr[0] = 0;
- }
-
-
- /*****************************************************************************/
- void GetDesDirName(
- StringPtr dirStr // Returned folder name string
- )
- /******************************************************************************
- Get name of folder specified in "desVRefNum/desDirID" and return in
- the specified string.
- ******************************************************************************/
- {
- CInfoPBRec ib;
-
- ib.dirInfo.ioVRefNum = gParms->desVRefNum;
- ib.dirInfo.ioDrDirID = gParms->desDirID;
- ib.dirInfo.ioNamePtr = dirStr;
- ib.dirInfo.ioFDirIndex = -1;
- if (PBGetCatInfoSync(&ib))
- dirStr[0] = 0;
- }
-
-
- /*****************************************************************************/
- void BuildItemString(
- StringPtr nameStr // Returned item string
- )
- /******************************************************************************
- Return the item name and type in the specified string.
- ******************************************************************************/
- {
- nameStr[0] = 0;
- StrAppend(gParms->itemIsFolder ? "\p(folder) “" : "\p(file) “", nameStr);
- StrAppend(gParms->itemName, nameStr);
- StrAppend("\p”", nameStr);
- }
-
-
- /*****************************************************************************/
- void BuildGroupStrings(
- StringPtr selGroupStr, // Returned selected groups string
- StringPtr envGroupStr // Returned environment groups string
- )
- /******************************************************************************
- Build a list of selected groups and a list of environment groups. Return
- the lists in the specified strings.
- ******************************************************************************/
- {
- short index;
- short count;
- short groupNum;
- unsigned long flags;
- Str255 tmpStr;
-
- ///// Build selected groups string /////
- index = 0;
- for (count = 0; count <= 15; count++)
- {
- if (gParms->groupAPFlags & (0x0001 << count))
- { // Group is selected - add to list
- selGroupStr[++index] = 'A' + count;
- selGroupStr[++index] = '/';
- }
- }
- selGroupStr[++index] = 'Q' + gParms->groupQUSel;
- selGroupStr[++index] = '/';
- selGroupStr[++index] = 'V' + gParms->groupVZSel;
-
- for (groupNum = 1; groupNum <= 96; groupNum++)
- {
- if (groupNum <= 32)
- flags = gParms->group32Flags;
- else if (groupNum <= 64)
- flags = gParms->group64Flags;
- else
- flags = gParms->group96Flags;
- if (flags & (0x00000001L << ((groupNum - 1) & 0x1F)))
- { // Group is selected - add to list
- if (index > 40)
- { // Max string length exceeded - truncate
- selGroupStr[++index] = '…';
- break;
- }
- selGroupStr[++index] = '/';
- NumToString(groupNum, tmpStr);
- selGroupStr[++index] = tmpStr[1];
- if (tmpStr[0] > 1)
- selGroupStr[++index] = tmpStr[2];
- }
- }
- selGroupStr[0] = index;
-
- ///// Build environment groups string /////
- envGroupStr[0] = 0;
-
- // Set monitor type
- if (gParms->groupEnvironFlags & siHookEnvBlackAndWhite)
- StrAppend("\pB&W", envGroupStr);
- if (gParms->groupEnvironFlags & siHookEnvColor)
- StrAppend("\pColor", envGroupStr);
-
- // Set processor type
- if (gParms->groupEnvironFlags & siHookEnv68KProcessor)
- StrAppend("\p/68K-Mac", envGroupStr);
- if (gParms->groupEnvironFlags & siHookEnvPPCProcessor)
- StrAppend("\p/PowerMac", envGroupStr);
-
- // Set FPU
- if (gParms->groupEnvironFlags & siHookEnv68KWithFPU)
- StrAppend("\p/FPU", envGroupStr);
- if (gParms->groupEnvironFlags & siHookEnv68KWithoutFPU)
- StrAppend("\p/NoFPU", envGroupStr);
-
- // Set system version
- if (gParms->groupEnvironFlags & siHookEnvSystem6OrLower)
- StrAppend("\p/Sys-6", envGroupStr);
- if (gParms->groupEnvironFlags & siHookEnvSystem7OrHigher)
- StrAppend("\p/Sys-7", envGroupStr);
-
- // Set fat install type
- if (gParms->groupEnvironFlags & siHookEnvInstallFat)
- StrAppend("\p/Fat", envGroupStr);
- if (gParms->groupEnvironFlags & siHookEnvInstall68KOnly)
- StrAppend("\p/68K-only", envGroupStr);
- if (gParms->groupEnvironFlags & siHookEnvInstallPPCOnly)
- StrAppend("\p/PPC-only", envGroupStr);
- }
-
-
- /*****************************************************************************/
- void StrAppend(
- StringPtr srcStr, // Source string
- StringPtr desStr // Destination string
- )
- /******************************************************************************
- Append the characters in the source string to the destination string.
- ******************************************************************************/
- {
- BlockMove(&srcStr[1], &desStr[desStr[0] + 1], srcStr[0]);
- desStr[0] += srcStr[0];
- }
-